<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <h1>{{msg}}---{{acceptMsg}}</h1>
        <son @data="acceptData"></son>
    </div>
    <template id="son">
        <div>
            <h1>{{msg}}</h1>
            <button @click="toFather">点击按钮，将自己的值传递给父组件</button>
        </div>
    </template>
    <script src="./js/vue.js"></script>
    <script>
        let son = {
            data() {
                return {
                    msg: "我是子组件",
                    sonMsg: "我是准备传递给父亲的值"
                }
            },
            methods: {
                toFather() {
                    this.$emit("data", this.sonMsg);
                }
            },
            template: "#son"
        }
        let vm = new Vue({
            el: '#app',
            data: {
                msg: "vue",
                acceptMsg: ""
            },
            methods: {
                acceptData(val) {
                    this.acceptMsg = val;
                }
            },
            components: {
                son
            }
        });
    </script>
</body>

</html>